package com.ecr.hub.database.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.ecr.hub.model.sillon.Sillon;

public class MapperSillon {

	//!! Attention au multiThread !!
	private static DateFormat df = new SimpleDateFormat("HH:mm");

	protected static ParameterizedRowMapper<Sillon> mapperSillon = new ParameterizedRowMapper<Sillon>() {
		public Sillon mapRow(ResultSet rs, int rowNum) throws SQLException {

			Sillon sillon = new Sillon();

			sillon.setId(rs.getInt("id"));
			sillon.setExtId(rs.getString("ext_id"));
			sillon.setTcmsTrainId(rs.getString("tcms_train_id"));
			sillon.setOrigin(rs.getString("origin"));
			sillon.setMovementDate(rs.getDate("movement_date"));
			sillon.setMovementTime(df.format(rs.getTime("movement_Time")));
			sillon.setDestination(rs.getString("destination"));
			sillon.setStatusId(rs.getInt("status_id"));
			sillon.setRealMovementDate(rs.getDate("real_movement_date"));
			sillon.setRealMovementTime(df.format(rs
					.getTime("real_movement_time")));
			sillon.setType(rs.getString("type"));
			sillon.setComment(rs.getString("comment"));
			sillon.setNbWagons(rs.getInt("nb_wagons"));
			sillon.setRailId(rs.getInt("rail_id"));
			sillon.setRailExtId(rs.getString("rail_ext_id"));
			sillon.setRailFormationExtId(rs.getString("rail_formation_ext_id"));
			sillon.setRailFormationId(rs.getInt("rail_formation_id"));
			sillon.setReverseSense(rs.getBoolean("reverse_sense"));
			sillon.setRailFormationLabel(rs.getString("rail_formation_label"));
			sillon.setCompositionFileName(rs.getString("compo_file_name"));
			sillon.setDateUpdate(rs.getDate("date_update"));
			sillon.setRailLabel(rs.getString("rail_label"));
			sillon.setLading(rs.getString("lading"));
			sillon.setEcrOwner(rs.getBoolean("ecr_owner"));
			sillon.setUpdated(rs.getBoolean("updated"));
			return sillon;
		}
	};
}